import { ref } from 'vue'
import { defineStore } from 'pinia'

export const useLoginStore = defineStore('login', () => {
  const autoLogin = ref(false)
  const setAutoLogin = (value) => {
    autoLogin.value = value
  }
  const token = ref('')
  const username = ref('')
  const password = ref('')
  const user = ref({  })
  const setData = (data) => {
    user.value = data
    token.value = data.token
  }
  const clearData = () => {
    autoLogin.value = false
    token.value = ''
    username.value = ''
    password.value = ''
    user.value = {}
  } 
  const setLoginData = (data) => {
    username.value = data.username
    password.value = data.password
  }
  const type = ref('')
  const setType = (value) => {
    type.value = value
  }
  return { autoLogin, setAutoLogin,token,setData,clearData,username,password,user,setLoginData,type ,setType}
},{persist: {
  paths:['autoLogin','token','username','user','type'],
}})
